<%@ page language="java" import="java.util.*,com.beans.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">

<title></title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    

<script type="text/javascript" src="js/jquery-1.8.0.js"></script> 
	<script type="text/javascript">
		$(function(){
			$("#ch_checkall,#top_ch_checkall").click(function(){
				if(this.checked){
					$("input[name=ck_id]").attr("checked","checked");
				}else{
					$("input[name=ck_id]").removeAttr("checked");
				}		
			});
					
			$("table tr").mouseover(function(){
				$(this).css("background","#D3EAEF");
				$(this).siblings().css("background","white");
			});
		});
	</script>

	<link rel="stylesheet" type="text/css" href="css/maintable.css" ></link>

</head>
		<script >
	//页面加载完，查询一级分类
		$(function(){
			$.ajax({
				type:"POST",
				url:"CateServlet.do",
				data:{flog:"search",parentId:"0"},
				async:false,
				dataType:"json",
				success:function(cates){
					
					$("select[name=bigCateId]").empty();
					$("select[name=bigCateId]").append("<option value=''>==请选择一级分类==</option>");
					$.map(cates,function(v,k){
						$("select[name=bigCateId]").append("<option value='"+v.id+"'>"+v.cateName+"</option>");
						if(v.id==${bigCateId}+""){
							$("select[name=bigCateId]").val(${bigCateId});
						}
					});

				}
			});
		});
	</script>
	<script >
	//一级分类改变，查询二级分类
		$(function(){
			$("select[name=bigCateId]").change(function(){
				if($("select[name=bigCateId]").val()==""){
					$("select[name=smallCateId]").empty();
					$("select[name=smallCateId]").append("<option value=''>==请选择二级分类==</option>");
				}else{
					$.ajax({
						type:"POST",
						url:"CateServlet.do",
						data:{flog:"search",parentId:this.value},
						async:false,
						dataType:"json",
						success:function(cates){
							
							$("select[name=smallCateId]").empty();
							$("select[name=smallCateId]").append("<option value=''>==请选择二级分类==</option>");
							$.map(cates,function(v,k){
								$("select[name=smallCateId]").append("<option value='"+v.id+"'>"+v.cateName+"</option>");
								if(v.id==${smallCateId}+""){
									$("select[name=smallCateId]").val(${smallCateId});
								}
							});
						}
					});
				}
			});
		});
	</script>
	<script >
		$(function(){
			if(""!=${bigCateId}+""){
				$.ajax({
					type:"POST",
					url:"CateServlet.do",
					data:{flog:"search",parentId:${bigCateId}+""},
					async:false,
					dataType:"json",
					success:function(cates){
						
						$("select[name=smallCateId]").empty();
						$("select[name=smallCateId]").append("<option value=''>==请选择二级分类==</option>");
						$.map(cates,function(v,k){
							$("select[name=smallCateId]").append("<option value='"+v.id+"'>"+v.cateName+"</option>");
							if(v.id==${smallCateId}+""){
								$("select[name=smallCateId]").val(${smallCateId});
							}
						});
					}
				});
			}
		});
		
		function subForm(){
	    	$("#pageIndex").val("1");
	    	document.form1.submit();
		}
	</script>

<body>

			<div class ="div_title">
					<div class="div_titlename"> <img src="images/san_jiao.gif" ><span>商品列表</span></div>
					<div class="div_titleoper">
						<input type="checkbox" id="top_ch_checkall"/> 全选 <a href="admin_add.jsp"> <img src="images/add.gif"/>添加 </a> <a href="javascript:void(0)"><img src="images/del.gif"/>删除</a> </div>
			 </div>
				 
			 <form action="GoodsServlet.do?flog=manage"  name="form1" method="post">
				 所属大分类:<select name="bigCateId" >
								<option value="">==请选择一级分类==</option>
				  				</select>   
				  
				所属小分类:<select name="smallCateId" >
							<option value="">==请选择二级分类==</option>
				 		 </select> 
				<input name="seach" value="${seach}"> <button onclick="subForm()">查询</button>
				 <table class="main_table" >
				       <tr>
				 				<th><input type="checkbox" id="ch_checkall" /></th>	<th>名称</th> 	<th>单位</th>	<th>单价</th>  <th>大分类</th> 	<th>小分类</th><th>操作</th>
				 		</tr>
				 		
				 		<c:forEach var="item" items="${goodsList }">
					 		<tr>
					 				<td>
					 					<input type="checkbox" name="ck_id" value="69" /> 
					 				</td>
					 				<td>${item.goodsName}</td>	
					 				<td>
					 					${item.unit}
					 				</td>	
					 				<td>${item.price}</td>
					 				<td> 
					 					<c:forEach var="cate" items="${cateList }">
					 						<c:if test="${item.bigCateId==cate.id}">
					 							${cate.cateName}
					 						</c:if>
					 					</c:forEach>
					 				
					 				</td>	
					 				
					 				<td>
					 					<c:forEach var="cate" items="${cateList }">
					 						<c:if test="${item.smallCateId==cate.id}">
					 							${cate.cateName}
					 						</c:if>
					 					</c:forEach>	
					 				</td>	
					 				
					 				
					 				<td>
					 					<a href="GoodsServlet.do?flog=showGoods&id=${item.id}">查看</a> |  
					 					<a href="GoodsServlet.do?flog=goChangeGoods&id=${item.id}">修改</a> |  	
					 			   		<a href="GoodsServlet.do?flog=delGoods&id=${item.id}&pageIndex=${page.pageIndex }&bigCateId=${bigCateId}&smallCateId=${smallCateId}&seach=${seach}" onclick="return confirm('是否删除')">删除</a> 
					 				</td>
					 		</tr>
				 		</c:forEach>
				</table>
				
				
				<div class="div_page" >
					  <div class="div_page_left">    共有 <label>${page.rowCount}</label> 条记录，当前第 <label>${page.pageIndex }</label> 页，共 <label>${page.pageCount }</label> 页	</div>		
					  <div class="div_page_right" > 	 
					  			<c:choose>
									<c:when test="${page.hasPre }">
										<a href="GoodsServlet.do?flog=manage&pageIndex=1&bigCateId=${bigCateId}&smallCateId=${smallCateId}&seach=${seach}">首页</a>
										<a href="GoodsServlet.do?flog=manage&pageIndex=${page.pageIndex-1 }&bigCateId=${bigCateId}&smallCateId=${smallCateId}&seach=${seach}">上一页</a>
									</c:when>
									
									<c:otherwise>
							        		首页
							        		前一页
							        </c:otherwise>
								</c:choose>
								
								<c:choose>
									<c:when test="${page.hasNext }">
										<a href="GoodsServlet.do?flog=manage&pageIndex=${page.pageCount }&bigCateId=${bigCateId}&smallCateId=${smallCateId}&seach=${seach}">尾页</a>
										<a href="GoodsServlet.do?flog=manage&pageIndex=${page.pageIndex+1 }&bigCateId=${bigCateId}&smallCateId=${smallCateId}&seach=${seach}">下一页</a>
									</c:when>
									
									<c:otherwise>
							        		尾页
							        		下一页
							        </c:otherwise>
								</c:choose>

					  	  <input type="submit" value="转到"/>
					  	 <input type="text" name="pageIndex" id="pageIndex" value="${page.pageIndex }" /> 页
					  	
					   </div>
				</div>
				
				</form>

  </body>
</html>	
